package com.xiaou.buss.admin.menu.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.service.BaseServiceImpl;
import com.xiaou.buss.admin.menu.dao.MenuDao;
import com.xiaou.buss.admin.menu.entity.Menu;
import com.xiaou.buss.admin.menu.entity.MenuBO;
import com.xiaou.buss.admin.menu.service.MenuService;
import com.xiaou.buss.admin.rolemenu.entity.RoleMenu;
import com.xiaou.buss.admin.rolemenu.service.RoleMenuService;

/**
 * 
 * <br>
 * <b>功能：</b>MenuService<br>
 */
@Service("menuService")
public class  MenuServiceImpl  extends BaseServiceImpl implements MenuService {
  Logger logger = LoggerFactory.getLogger(getClass());
	

  	@Autowired
  	private RoleMenuService roleMenuService;
	@Autowired
    private MenuDao dao;

		
	public MenuDao getDao() {
		return dao;
	}


	@Override
	public List<MenuBO> findUserMenu(String userId) {
//		return dao.findUserMenu(userId);
		List<MenuBO> menus = dao.findUserMenu(userId);
		return menus;
	}


	@Override
	public List<Menu> findRoleMenu(String roleId) {
		return dao.findRoleMenu(roleId);
	}

	@Override
	public List<MenuBO> findRoleMenuCheck(String roleId) {
		return dao.findRoleMenuCheck(roleId);
	}


	@Override
	public int queryMaxParentCode() {
		return dao.queryMaxParentCode();
	}


	@Override
	public int queryMaxChildCode(Integer parentCode) {
		return dao.queryMaxChildCode(parentCode);
	}


	@Override
	public void deleteParent(Integer menuId) {
		List<Menu> menuList = dao.queryChlidMenu(menuId);
		for(Menu m:menuList){
			roleMenuService.delByMenuId(m.getId());
		}
		dao.deleteParent(menuId);
		roleMenuService.delByMenuId(menuId);
	}


	@Override
	public void deleteChild(Integer menuId) {
		dao.delete(menuId);
		roleMenuService.delByMenuId(menuId);
	}


	@Override
	public List<MenuBO> findAllMenu() {
		return dao.findAllMenu();
	}


	

}
